import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      // 首页
      { path: '/', component: () => import('@/views/Home') },
      // 商品详情
      { path: '/goods/:id', component: () => import('@/views/Goods') },
      // 分类
      { path: '/category/:id', component: () => import('@/views/Category') },
      {
        path: '/category/sub/:id',
        component: () => import('@/views/Category/Sub')
      },
      {
        path: '/cart',
        component: () => import('@/views/Cart')
      },
      {
        path: '/settlement',
        component: () => import('@/views/Settlement')
      },
      {
        path: '/pay',
        component: () => import('@/views/Pay')
      },
      {
        path: '/pay/callback',
        component: () => import('@/views/Pay/callback.vue')
      },
      {
        path: '/member',
        component: () => import('@/views/Member/Layout'),
        children: [
          { path: '', component: () => import('@/views/Member/Home') },
          { path: 'order', component: () => import('@/views/Member/Order') }
        ]
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/Login')
  },
  {
    path: '/playground',
    component: () => import('@/views/Playground')
  },
  {
    path: '/login/callback',
    component: () => import('@/views/Login/callback')
  }
]

// Vue2 => new VueRouter()
// Vue3 => createRouter
const router = createRouter({
  // 使用 Hash 模式的路由
  history: createWebHashHistory(),
  routes,
  scrollBehavior: () => ({ x: 0, y: 0 })
})

export default router
